﻿using Microsoft.AspNetCore.Mvc;
using ProjectScheduling_web.dao;
using ProjectScheduling_web.model;

namespace ProjectScheduling_web.Controllers.Staff
{
    public class ProjectController : BController
    {
        /// <summary>
        /// 未排期名称列表
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>        
        [HttpGet]
        public ActionResult NoPrepareProjects(string key, int page = 1, int row = 10)
        {
            var states = new List<Enum_ProjectState> { Enum_ProjectState.待排期, Enum_ProjectState.挂起 };
            var sps = new List<string> { "副总经理已审批", "总经理已审批" };
            var lst = ProjectsDao.Base.FindAll(
                page, row,
                it =>
           (string.IsNullOrEmpty(key) || (it.Name != null && it.Name.Contains(key))) &&
            it.ApproveState != null && sps.Contains(it.ApproveState) &&
            states.Contains(it.State)
            );
            return Success(lst);

        }
        [HttpGet]
        public ActionResult Detail(int id)
        {
            var project = ProjectsDao.Base.Find(id);
            if (project == null) return Fail("当前项目不存在");
            project.ProjectType = ProjectTypesDao.Base.Find(project.ProjectTypeId);
            project.SalespersonName = MemberDao.Base.Find(project.SalespersonId)?.Name;
            return Success(project);
        }
    }
}
